home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tcsel003.zip / GLOBALS.PAS < prev    next >
Pascal/Delphi Source File  |  1992-11-07  |  19KB  |  352 lines

  1. unit globals;
  2.  
  3. { Use this unit for procedures, functions and variables that every program you
  4.   write will share.
  5. }
  6.  
  7. interface
  8.  
  9. uses 
  10.   dos;
  11.   
  12. type
  13.   str1 = string[1]; str2 = string[2]; str3 = string[3];
  14.   str4 = string[4]; str5 = string[5]; str6 = string[6];
  15.   str7 = string[7]; str8 = string[8]; str9 = string[9];
  16.   str10 = string[10]; str11 = string[11]; str12 = string[12];
  17.   str13 = string[13]; str14 = string[14]; str15 = string[15];
  18.   str16 = string[16]; str17 = string[17]; str18 = string[18];
  19.   str19 = string[19]; str20 = string[20]; str21 = string[21];
  20.   str22 = string[22]; str23 = string[23]; str24 = string[24];
  21.   str25 = string[25]; str26 = string[26]; str27 = string[27];
  22.   str28 = string[28]; str29 = string[29]; str30 = string[30];
  23.   str31 = string[31]; str32 = string[32]; str33 = string[33];
  24.   str34 = string[34]; str35 = string[35]; str36 = string[36];
  25.   str37 = string[37]; str38 = string[38]; str39 = string[39];
  26.   str40 = string[40]; str41 = string[41]; str42 = string[42];
  27.   str43 = string[43]; str44 = string[44]; str45 = string[45];
  28.   str46 = string[46]; str47 = string[47]; str48 = string[48];
  29.   str49 = string[49]; str50 = string[50]; str51 = string[51];
  30.   str52 = string[52]; str53 = string[53]; str54 = string[54];
  31.   str55 = string[55]; str56 = string[56]; str57 = string[57];
  32.   str58 = string[58]; str59 = string[59]; str60 = string[60];
  33.   str61 = string[61]; str62 = string[62]; str63 = string[63];
  34.   str64 = string[64]; str65 = string[65]; str66 = string[66];
  35.   str67 = string[67]; str68 = string[68]; str69 = string[69];
  36.   str70 = string[70]; str71 = string[71]; str72 = string[72];
  37.   str73 = string[73]; str74 = string[74]; str75 = string[75];
  38.   str76 = string[76]; str77 = string[77]; str78 = string[78];
  39.   str79 = string[79]; str80 = string[80]; str81 = string[81];
  40.   str82 = string[82]; str83 = string[83]; str84 = string[84];
  41.   str85 = string[85]; str86 = string[86]; str87 = string[87];
  42.   str88 = string[88]; str89 = string[89]; str90 = string[90];
  43.   str91 = string[91]; str92 = string[92]; str93 = string[93];
  44.   str94 = string[94]; str95 = string[95]; str96 = string[96];
  45.   str97 = string[97]; str98 = string[98]; str99 = string[99];
  46.   str100 = string[100]; str101 = string[101]; str102 = string[102];
  47.   str103 = string[103]; str104 = string[104]; str105 = string[105];
  48.   str106 = string[106]; str107 = string[107]; str108 = string[108];
  49.   str109 = string[109]; str110 = string[110]; str111 = string[111];
  50.   str112 = string[112]; str113 = string[113]; str114 = string[114];
  51.   str115 = string[115]; str116 = string[116]; str117 = string[117];
  52.   str118 = string[118]; str119 = string[119]; str120 = string[120];
  53.   str121 = string[121]; str122 = string[122]; str123 = string[123];
  54.   str124 = string[124]; str125 = string[125]; str126 = string[126];
  55.   str127 = string[127]; str128 = string[128]; str129 = string[129];
  56.   str130 = string[130]; str131 = string[131]; str132 = string[132];
  57.   str133 = string[133]; str134 = string[134]; str135 = string[135];
  58.   str136 = string[136]; str137 = string[137]; str138 = string[138];
  59.   str139 = string[139]; str140 = string[140]; str141 = string[141];
  60.   str142 = string[142]; str143 = string[143]; str144 = string[144];
  61.   str145 = string[145]; str146 = string[146]; str147 = string[147];
  62.   str148 = string[148]; str149 = string[149]; str150 = string[150];
  63.   str151 = string[151]; str152 = string[152]; str153 = string[153];
  64.   str154 = string[154]; str155 = string[155]; str156 = string[156];
  65.   str157 = string[157]; str158 = string[158]; str159 = string[159];
  66.   str160 = string[160]; str161 = string[161]; str162 = string[162];
  67.   str163 = string[163]; str164 = string[164]; str165 = string[165];
  68.   str166 = string[166]; str167 = string[167]; str168 = string[168];
  69.   str169 = string[169]; str170 = string[170]; str171 = string[171];
  70.   str172 = string[172]; str173 = string[173]; str174 = string[174];
  71.   str175 = string[175]; str176 = string[176]; str177 = string[177];
  72.   str178 = string[178]; str179 = string[179]; str180 = string[180];
  73.   str181 = string[181]; str182 = string[182]; str183 = string[183];
  74.   str184 = string[184]; str185 = string[185]; str186 = string[186];
  75.   str187 = string[187]; str188 = string[188]; str189 = string[189];
  76.   str190 = string[190]; str191 = string[191]; str192 = string[192];
  77.   str193 = string[193]; str194 = string[194]; str195 = string[195];
  78.   str196 = string[196]; str197 = string[197]; str198 = string[198];
  79.   str199 = string[199]; str200 = string[200]; str201 = string[201];
  80.   str202 = string[202]; str203 = string[203]; str204 = string[204];
  81.   str205 = string[205]; str206 = string[206]; str207 = string[207];
  82.   str208 = string[208]; str209 = string[209]; str210 = string[210];
  83.   str211 = string[211]; str212 = string[212]; str213 = string[213];
  84.   str214 = string[214]; str215 = string[215]; str216 = string[216];
  85.   str217 = string[217]; str218 = string[218]; str219 = string[219];
  86.   str220 = string[220]; str221 = string[221]; str222 = string[222];
  87.   str223 = string[223]; str224 = string[224]; str225 = string[225];
  88.   str226 = string[226]; str227 = string[227]; str228 = string[228];
  89.   str229 = string[229]; str230 = string[230]; str231 = string[231];
  90.   str232 = string[232]; str233 = string[233]; str234 = string[234];
  91.   str235 = string[235]; str236 = string[236]; str237 = string[237];
  92.   str238 = string[238]; str239 = string[239]; str240 = string[240];
  93.   str241 = string[241]; str242 = string[242]; str243 = string[243];
  94.   str244 = string[244]; str245 = string[245]; str246 = string[246];
  95.   str247 = string[247]; str248 = string[248]; str249 = string[249];
  96.   str250 = string[250]; str251 = string[251]; str252 = string[252];
  97.   str253 = string[253]; str254 = string[254]; str255 = string[255];
  98.  
  99. const
  100.   MaxWord    = $ffff;
  101.   MinWord    = 0;
  102.   MinInt     = integer($8000);
  103.   MinLongint = $80000000;
  104.   UseCfg     = true;
  105.  
  106.   {Color constants:
  107.    Black     = 0; Blue   = 1; Green   = 2; Cyan   = 3; Red   = 4;
  108.    Magenta   = 5; Brown  = 6; LtGray  = 7;
  109.    DkGray    = 8; LtBlue = 9; LtGreen = A; LtCyan = B; LtRed = C;
  110.    LtMagenta = D; Yellow = E; White   = F
  111.    }
  112.  
  113. const  Blink               = $80;
  114.  
  115.   {Screen color constants}
  116. const   BlackOnBlack       = $00;          BlueOnBlack        = $01;
  117. const   BlackOnBlue        = $10;          BlueOnBlue         = $11;
  118. const   BlackOnGreen       = $20;          BlueOnGreen        = $21;
  119. const   BlackOnCyan        = $30;          BlueOnCyan         = $31;
  120. const   BlackOnRed         = $40;          BlueOnRed          = $41;
  121. const   BlackOnMagenta     = $50;          BlueOnMagenta      = $51;
  122. const   BlackOnBrown       = $60;          BlueOnBrown        = $61;
  123. const   BlackOnLtGray      = $70;          BlueOnLtGray       = $71;
  124. const   GreenOnBlack       = $02;          CyanOnBlack        = $03;
  125. const   GreenOnBlue        = $12;          CyanOnBlue         = $13;
  126. const   GreenOnGreen       = $22;          CyanOnGreen        = $23;
  127. const   GreenOnCyan        = $32;          CyanOnCyan         = $33;
  128. const   GreenOnRed         = $42;          CyanOnRed          = $43;
  129. const   GreenOnMagenta     = $52;          CyanOnMagenta      = $53;
  130. const   GreenOnBrown       = $62;          CyanOnBrown        = $63;
  131. const   GreenOnLtGray      = $72;          CyanOnLtGray       = $73;
  132. const   RedOnBlue          = $14;          MagentaOnBlue      = $15;
  133. const   RedOnGreen         = $24;          MagentaOnGreen     = $25;
  134. const   RedOnCyan          = $34;          MagentaOnCyan      = $35;
  135. const   RedOnRed           = $44;          MagentaOnRed       = $45;
  136. const   RedOnMagenta       = $54;          MagentaOnMagenta   = $55;
  137. const   RedOnBrown         = $64;          MagentaOnBrown     = $65;
  138. const   RedOnLtGray        = $74;          MagentaOnLtGray    = $75;
  139. const   BrownOnBlack       = $06;          LtGrayOnBlack      = $07;
  140. const   BrownOnBlue        = $16;          LtGrayOnBlue       = $17;
  141. const   BrownOnGreen       = $26;          LtGrayOnGreen      = $27;
  142. const   BrownOnCyan        = $36;          LtGrayOnCyan       = $37;
  143. const   BrownOnRed         = $46;          LtGrayOnRed        = $47;
  144. const   BrownOnMagenta     = $56;          LtGrayOnMagenta    = $57;
  145. const   BrownOnBrown       = $66;          LtGrayOnBrown      = $67;
  146. const   BrownOnLtGray      = $76;          LtGrayOnLtGray     = $77;
  147. const   DkGrayOnBlack      = $08;          LtBlueOnBlack      = $09;
  148. const   DkGrayOnBlue       = $18;          LtBlueOnBlue       = $19;
  149. const   DkGrayOnGreen      = $28;          LtBlueOnGreen      = $29;
  150. const   DkGrayOnCyan       = $38;          LtBlueOnCyan       = $39;
  151. const   DkGrayOnRed        = $48;          LtBlueOnRed        = $49;
  152. const   DkGrayOnMagenta    = $58;          LtBlueOnMagenta    = $59;
  153. const   DkGrayOnBrown      = $68;          LtBlueOnBrown      = $69;
  154. const   DkGrayOnLtGray     = $78;          LtBlueOnLtGray     = $79;
  155. const   LtGreenOnBlack     = $0A;          LtCyanOnBlack      = $0B;
  156. const   LtGreenOnBlue      = $1A;          LtCyanOnBlue       = $1B;
  157. const   LtGreenOnGreen     = $2A;          LtCyanOnGreen      = $2B;
  158. const   LtGreenOnCyan      = $3A;          LtCyanOnCyan       = $3B;
  159. const   LtGreenOnRed       = $4A;          LtCyanOnRed        = $4B;
  160. const   LtGreenOnMagenta   = $5A;          LtCyanOnMagenta    = $5B;
  161. const   LtGreenOnBrown     = $6A;          LtCyanOnBrown      = $6B;
  162. const   LtGreenOnLtGray    = $7A;          LtCyanOnLtGray     = $7B;
  163. const   LtRedOnBlue        = $1C;          LtMagentaOnBlue    = $1D;
  164. const   LtRedOnGreen       = $2C;          LtMagentaOnGreen   = $2D;
  165. const   LtRedOnCyan        = $3C;          LtMagentaOnCyan    = $3D;
  166. const   LtRedOnRed         = $4C;          LtMagentaOnRed     = $4D;
  167. const   LtRedOnMagenta     = $5C;          LtMagentaOnMagenta = $5D;
  168. const   LtRedOnBrown       = $6C;          LtMagentaOnBrown   = $6D;
  169. const   LtRedOnLtGray      = $7C;          LtMagentaOnLtGray  = $7D;
  170. const   YellowOnBlack      = $0E;          WhiteOnBlack       = $0F;
  171. const   YellowOnBlue       = $1E;          WhiteOnBlue        = $1F;
  172. const   YellowOnGreen      = $2E;          WhiteOnGreen       = $2F;
  173. const   YellowOnCyan       = $3E;          WhiteOnCyan        = $3F;
  174. const   YellowOnRed        = $4E;          WhiteOnRed         = $4F;
  175. const   YellowOnMagenta    = $5E;          WhiteOnMagenta     = $5F;
  176. const   YellowOnBrown      = $6E;          WhiteOnBrown       = $6F;
  177. const   YellowOnLtGray     = $7E;          WhiteOnLtGray      = $7F;
  178. const   BlackOnDkGray     = Blink + $00;   BlueOnDkGray      = Blink + $01;
  179. const   BlackOnLtBlue     = Blink + $10;   BlueOnLtBlue      = Blink + $11;
  180. const   BlackOnLtGreen    = Blink + $20;   BlueOnLtGreen     = Blink + $21;
  181. const   BlackOnLtCyan     = Blink + $30;   BlueOnLtCyan      = Blink + $31;
  182. const   BlackOnLtRed      = Blink + $40;   BlueOnLtRed       = Blink + $41;
  183. const   BlackOnLtMagenta  = Blink + $50;   BlueOnLtMagenta   = Blink + $51;
  184. const   BlackOnYellow     = Blink + $60;   BlueOnYellow      = Blink + $61;
  185. const   BlackOnWhite      = Blink + $70;   BlueOnWhite       = Blink + $71;
  186. const   GreenOnDkGray     = Blink + $02;   CyanOnDkGray      = Blink + $03;
  187. const   GreenOnLtBlue     = Blink + $12;   CyanOnLtBlue      = Blink + $13;
  188. const   GreenOnLtGreen    = Blink + $22;   CyanOnLtGreen     = Blink + $23;
  189. const   GreenOnLtCyan     = Blink + $32;   CyanOnLtCyan      = Blink + $33;
  190. const   GreenOnLtRed      = Blink + $42;   CyanOnLtRed       = Blink + $43;
  191. const   GreenOnLtMagenta  = Blink + $52;   CyanOnLtMagenta   = Blink + $53;
  192. const   GreenOnYellow     = Blink + $62;   CyanOnYellow      = Blink + $63;
  193. const   GreenOnWhite      = Blink + $72;   CyanOnWhite       = Blink + $73;
  194. const   RedOnDkGray       = Blink + $04;   MagentaOnDkGray   = Blink + $05;
  195. const   RedOnLtBlue       = Blink + $14;   MagentaOnLtBlue   = Blink + $15;
  196. const   RedOnLtGreen      = Blink + $24;   MagentaOnLtGreen  = Blink + $25;
  197. const   RedOnLtCyan       = Blink + $34;   MagentaOnLtCyan   = Blink + $35;
  198. const   RedOnLtRed        = Blink + $44;   MagentaOnLtRed    = Blink + $45;
  199. const   RedOnLtMagenta    = Blink + $54;   MagentaOnLtMagenta= Blink + $55;
  200. const   RedOnYellow       = Blink + $64;   MagentaOnYellow   = Blink + $65;
  201. const   RedOnWhite        = Blink + $74;   MagentaOnWhite    = Blink + $75;
  202. const   BrownOnDkGray     = Blink + $06;   LtGrayOnDkGray    = Blink + $07;
  203. const   BrownOnLtBlue     = Blink + $16;   LtGrayOnLtBlue    = Blink + $17;
  204. const   BrownOnLtGreen    = Blink + $26;   LtGrayOnLtGreen   = Blink + $27;
  205. const   BrownOnLtCyan     = Blink + $36;   LtGrayOnLtCyan    = Blink + $37;
  206. const   BrownOnLtRed      = Blink + $46;   LtGrayOnLtRed     = Blink + $47;
  207. const   BrownOnLtMagenta  = Blink + $56;   LtGrayOnLtMagenta = Blink + $57;
  208. const   BrownOnYellow     = Blink + $66;   LtGrayOnYellow    = Blink + $67;
  209. const   BrownOnWhite      = Blink + $76;   LtGrayOnWhite     = Blink + $77;
  210. const   DkGrayOnDkGray    = Blink + $08;   LtBlueOnDkGray    = Blink + $09;
  211. const   DkGrayOnLtBlue    = Blink + $18;   LtBlueOnLtBlue    = Blink + $19;
  212. const   DkGrayOnLtGreen   = Blink + $28;   LtBlueOnLtGreen   = Blink + $29;
  213. const   DkGrayOnLtCyan    = Blink + $38;   LtBlueOnLtCyan    = Blink + $39;
  214. const   DkGrayOnLtRed     = Blink + $48;   LtBlueOnLtRed     = Blink + $49;
  215. const   DkGrayOnLtMagenta = Blink + $58;   LtBlueOnLtMagenta = Blink + $59;
  216. const   DkGrayOnYellow    = Blink + $68;   LtBlueOnYellow    = Blink + $69;
  217. const   DkGrayOnWhite     = Blink + $78;   LtBlueOnWhite     = Blink + $79;
  218. const   LtGreenOnDkGray   = Blink + $0A;   LtCyanOnDkGray    = Blink + $0B;
  219. const   LtGreenOnLtBlue   = Blink + $1A;   LtCyanOnLtBlue    = Blink + $1B;
  220. const   LtGreenOnLtGreen  = Blink + $2A;   LtCyanOnLtGreen   = Blink + $2B;
  221. const   LtGreenOnLtCyan   = Blink + $3A;   LtCyanOnLtCyan    = Blink + $3B;
  222. const   LtGreenOnLtRed    = Blink + $4A;   LtCyanOnLtRed     = Blink + $4B;
  223. const   LtGreenOnLtMagenta= Blink + $5A;   LtCyanOnLtMagenta = Blink + $5B;
  224. const   LtGreenOnYellow   = Blink + $6A;   LtCyanOnYellow    = Blink + $6B;
  225. const   LtGreenOnWhite    = Blink + $7A;   LtCyanOnWhite     = Blink + $7B;
  226. const   LtRedOnDkGray     = Blink + $0C;   LtMagentaOnDkGray = Blink + $0D;
  227. const   LtRedOnLtBlue     = Blink + $1C;   LtMagentaOnLtBlue = Blink + $1D;
  228. const   LtRedOnLtGreen    = Blink + $2C;   LtMagentaOnLtGreen= Blink + $2D;
  229. const   LtRedOnLtCyan     = Blink + $3C;   LtMagentaOnLtCyan = Blink + $3D;
  230. const   LtRedOnLtRed      = Blink + $4C;   LtMagentaOnLtRed  = Blink + $4D;
  231. const   LtRedOnLtMagenta  = Blink + $5C;   LtMagentaOnLtMagenta= Blink + $5D;
  232. const   LtRedOnYellow     = Blink + $6C;   LtMagentaOnYellow = Blink + $6D;
  233. const   LtRedOnWhite      = Blink + $7C;   LtMagentaOnWhite  = Blink + $7D;
  234. const   YellowOnDkGray    = Blink + $0E;   WhiteOnDkGray     = Blink + $0F;
  235. const   YellowOnLtBlue    = Blink + $1E;   WhiteOnLtBlue     = Blink + $1F;
  236. const   YellowOnLtGreen   = Blink + $2E;   WhiteOnLtGreen    = Blink + $2F;
  237. const   YellowOnLtCyan    = Blink + $3E;   WhiteOnLtCyan     = Blink + $3F;
  238. const   YellowOnLtRed     = Blink + $4E;   WhiteOnLtRed      = Blink + $4F;
  239. const   YellowOnLtMagenta = Blink + $5E;   WhiteOnLtMagenta  = Blink + $5F;
  240. const   YellowOnYellow    = Blink + $6E;   WhiteOnYellow     = Blink + $6F;
  241. const   YellowOnWhite     = Blink + $7E;   WhiteOnWhite      = Blink + $7F;
  242.  
  243. var
  244.   TempStr    : string;
  245.   TempStrLen : byte absolute TempStr;
  246.   
  247. function Exist(fn: str80): boolean;
  248. { Returns true if file fn exists in the current directory                    }
  249.  
  250. function ExistsOnPath(var fn: str80): boolean;
  251. { Returns true if file fn exists in any directory specified in the current   }
  252. { path and changes fn to a fully qualified path/file.                        }
  253.  
  254. function StrUpCase(s : string): string;
  255. { Returns an upper case string from s. Applicable to the English language.   }
  256.  
  257. function StrLowCase(s : string): string;
  258. { Returns a string = to s with all upper case characters converted to lower  }
  259.  
  260. function Asc2Str(var s; max: byte): string;
  261. { Converts an ASCIIZ string to a Turbo Pascal string with a maximum length   }
  262. { of max characters.                                                         }
  263.  
  264. procedure Str2Asc(s: string; var ascStr; max: word);
  265. { Converts a TP string to an ASCIIZ string of no more than max length.       }
  266. { WARNING:  No checks are made that there is sufficient room in destination  }
  267. {           variable.                                                        }
  268.  
  269. function LastPos(ch: char; s: string): byte;
  270. { Returns the last position of ch in s                                       }
  271.  
  272. procedure CheckIO(a: byte);
  273.  
  274. implementation
  275.  
  276. function Exist(fn: str80): boolean;
  277.   begin
  278.     TempStrLen := 0;
  279.     TempStr    := FSearch(fn,'');
  280.     Exist      := TempStrLen <> 0;
  281.   end; { Exist }
  282.  
  283. function ExistsOnPath(var fn: str80): boolean;
  284.   begin
  285.     TempStrLen   := 0;
  286.     TempStr      := FSearch(fn,GetEnv('PATH'));
  287.     ExistsOnPath := TempStrLen <> 0;
  288.     fn           := FExpand(TempStr);
  289.   end; { ExistsOnPath }
  290.  
  291. function StrUpCase(s : string): string;
  292.   var x : byte;
  293.   begin
  294.     StrUpCase[0] := s[0];
  295.     for x := 1 to length(s) do
  296.       StrUpCase[x] := Upcase(s[x]);
  297.   end; { StrUpCase }
  298.  
  299. function StrLowCase(s : string): string;
  300.   var x : byte;
  301.   begin
  302.     StrLowCase[0] := s[0];
  303.     for x := 1 to length(s) do
  304.       case s[x] of
  305.       'a'..'z': StrLowCase[x] := chr(ord(s[x]) and $df);
  306.       else StrLowCase[x] := s[x];
  307.       end; { case }
  308.   end; { StrLowCase }
  309.  
  310. function Asc2Str(var s; max: byte): string;
  311.   var starray  : array[1..255] of char absolute s;
  312.       len      : integer;
  313.   begin
  314.     len        := pos(#0,starray)-1;                       { Get the length }
  315.     if (len > max) or (len < 0) then               { length exceeds maximum }
  316.       len      := max;                                  { so set to maximum }
  317.     Asc2Str    := starray;
  318.     Asc2Str[0] := chr(len);                                    { Set length }
  319.   end;  { Asc2Str }
  320.  
  321. procedure Str2Asc(s: string; var ascStr; max: word);
  322.   begin
  323.     FillChar(AscStr,max,0);
  324.     if length(s) < max then
  325.       move(s[1],AscStr,length(s))
  326.     else
  327.       move(s[1],AscStr,max);
  328.   end; { Str2Asc }
  329.  
  330.  
  331. function LastPos(ch: char; s: string): byte;
  332.   var x : word;
  333.   begin
  334.     x := succ(length(s));
  335.     repeat
  336.       dec(x);
  337.     until (s[x] = ch) or (x = 0);
  338.   end; { LastPos }
  339.  
  340. procedure CheckIO(a: byte);
  341.   var e : integer;
  342.   begin
  343.     e := IOResult;
  344.     if e <> 0 then begin
  345.       writeln('I/O error ',e,' section ',a);
  346.       halt(e);
  347.     end;
  348.   end; { CheckIO }
  349.  
  350. end. { Globals }
  351.   
  352.